<#import '/ftlLibrary/properteisVariable.ftl' as pv/>
<style>
	.bootbox-close-button {
		width: 19px;
		height: 19px;
		border: none;
		cursor: pointer;
		-webkit-appearance: none;
		float: right;
		top: 4px;
		left: -5px;
		position: relative;
		background: #E9F5FF url("assets/img/nav-img/icon_close.png") no-repeat 0 0;
	}
	.sysSchoolEdit .modal-dialog {
		width: 60% !important;
	}

	.sysSchoolEdit .modal-body {
		padding-bottom: 0;
	}
	input[type="text"],input[type="password"],input[type="email"],select{
		height: 30px!important;
		border-radius: 5px!important;
	}
	.sysSchoolEdit .widget-body {
		box-shadow: none;
		background-color: #fff;
	}
</style>
	<div class="col-lg-12 col-sm-12 col-xs-12">
			<div class="modal-header">
				<button type="button" class="bootbox-close-button close" data-dismiss="modal" aria-hidden="true">x</button>
				<h4 class="modal-title">${(editModel=='add')?string('新增','编辑')}</h4>
			</div>
			<div class="widget-body">
				<div class="row">
					<form class="editForm" action="${saveUrl}" method="post" responseType="JSON" role="form" id="editForm_${serializeNum}"
						data-bv-submitButtons="#editFormSubmitBtn_${serializeNum}"
						data-bv-message="This value is not valid"
						data-bv-feedbackicons-valid="glyphicon glyphicon-ok"
						data-bv-feedbackicons-invalid="glyphicon glyphicon-remove"
						data-bv-feedbackicons-validating="glyphicon glyphicon-refresh">
						<input type="hidden" name="id" value="${editEntity.id}">
						<#if (true && editModel=='add')||(true && editModel=='edit')>
							<div class="col-xm-12 col-sm-12 col-lg-12">
								<div class="form-group">
									<label for="schoolName" class="col-xm-2 col-sm-2 col-lg-2 control-label no-padding-right"><span style="color: red">*</span>园所名称：</label>
									<div class="col-xm-4 col-sm-4 col-lg-4">

										<input data-bv-remote="true"
											   data-bv-remote-url="sysSchoolController/verificationSchoolName.do?id=${editEntity.id}"
											   data-bv-remote-message="园所名称已存在！" required="required" onkeyup="inputValueLength(this,'noSymbol')"
											   data-bv-message="请填写园所名称！" name="schoolName" alt="账号名称"
											   id="schoolName" placeholder="园所名称" type="text" title="园所名称"
											   class="form-control" value="${editEntity.schoolName}"/>
										<span class="text"></span>
									</div>
								</div>
							</div>
						</#if>

						<#if (true && editModel=='add')||(true && editModel=='edit')>
							<div class="col-xm-12 col-sm-12 col-lg-12">
								<div class="col-xm-6 col-sm-6 col-lg-6">
									<div class="form-group">
										<label class="col-lg-4 col-sm-4 col-xs-4 control-label no-padding-right"><span style="color: red">*</span>园所类型：</label>
										<div class="col-lg-6 col-sm-6 col-xs-6">
											<select name="type" class="form-control" required="required">
												<option value="">请选择</option>
												<@dictionary groupCode="schoolType";dics>
												<#list dics as dic>
													<#if editEntity.type == dic.code>
														<option value="${dic.code}" selected="selected">${dic.value}</option>
														<#else>
															<option value="${dic.code}">${dic.value}</option>
													</#if>
												</#list>
											</@dictionary>
											</select>
										</div>
									</div>
								</div>
							</div>
						</#if>

						<#if (true && editModel=='add')||(true && editModel=='edit')>
							<div class="col-xm-12 col-sm-12 col-lg-12">
								<div class="form-group">
									<label class="col-xm-2 col-sm-2 col-lg-2 control-label no-padding-right"><span style="color: red">*</span>所属城区：</label>
									<div class="col-xm-10 col-sm-10 col-lg-10">
										<select data-bv-message="请选择省！" id="editSchoolProvince" name="schoolProvince" class="editSchoolProvince col-xm-3 col-sm-3 col-lg-3" required="required" value="${editEntity.schoolProvince}">
										</select>
										<select id="editSchoolCity" name="schoolCity" class="editSchoolCity col-xm-3 col-sm-3 col-lg-3" value="${editEntity.schoolCity}">
										</select>
										<select id="editSchoolRegion" name="schoolRegion" class="editSchoolRegion col-xm-3 col-sm-3 col-lg-3" value="${editEntity.schoolRegion}">
										</select>
										<label class="col-xm-3 col-sm-3 col-lg-3 no-padding">
											<input required="required" onkeyup="inputValueLength(this,'noSymbol')"
												   data-bv-message="请填写详细地址！" name="schoolAddress" alt="详细地址"
												   id="schoolAddress" placeholder="详细地址" type="text" title="详细地址"
												   class="form-control" value="${editEntity.schoolAddress}"/>
										</label>
									</div>
								</div>
							</div>
						</#if>

						<div class="col-xm-12 col-sm-12 col-lg-12">
							<#if (true && editModel=='add')||(true && editModel=='edit')>
								<div class="col-xm-6 col-sm-6 col-lg-6">
									<div class="form-group">
										<label for="contractNum" class="col-xm-4 col-sm-4 col-lg-4 control-label no-padding-right"><span style="color: red">*</span>合同编码：</label>
										<div class="col-xm-6 col-sm-6 col-lg-6">
											<input data-bv-remote="true"
												   data-bv-remote-url="sysSchoolController/verificationContractNum.do?id=${editEntity.id}"
												   data-bv-remote-message="合同编码已存在！" required="required" onkeyup="inputValueLength(this,'englishNumber')"
												   data-bv-message="请输入合同编码！" name="contractNum" alt="合同编码"
												   id="contractNum" placeholder="合同编码" type="text" title="合同编码"
												   class="form-control" value="${editEntity.contractNum}"/>
											<span class="text"></span>
										</div>
									</div>
								</div>
							</#if>

							<#if (false && editModel=='add')||(true && editModel=='edit')>
								<div class="col-xm-6 col-sm-6 col-lg-6">
									<div class="form-group">
										<label for="schoolCode" class="col-xm-4 col-sm-4 col-lg-4 control-label no-padding-right"><span style="color: red">*</span>园所编码：</label>
										<div class="col-xm-6 col-sm-6 col-lg-6">
											<input data-bv-message="The field is not valid" readonly name="schoolCode" onkeyup="inputValueLength(this,'englishNumber')"
												   alt="园所编码" id="schoolCode" placeholder="园所编码" type="text"
												   title="园所编码" class="form-control" value="${editEntity.schoolCode}"/>
											<span class="text"></span>
										</div>
									</div>
								</div>
							</#if>
						</div>

						<div class="col-xm-12 col-sm-12 col-lg-12">
							<#if (true && editModel=='add')||(true && editModel=='edit')>
								<div class="col-xm-6 col-sm-6 col-lg-6">
									<div class="form-group">
										<label for="schoolPhone" class="col-xm-4 col-sm-4 col-lg-4 control-label no-padding-right"><span style="color: red">*</span>联系方式：</label>
										<div class="col-xm-6 col-sm-6 col-lg-6">
											<input data-bv-message="请输入联系方式"  required="required" onblur="checkPhoneIsSame(this)" maxlength="11"
												   name="schoolPhone" alt="联系方式" id="schoolPhone" placeholder="联系方式"
												   data-bv-regexp="true"
												   data-bv-regexp-regexp="^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$"
												   data-bv-regexp-message="请输入正确的联系电话!"
												   type="text" title="联系方式" class="form-control" value="${editEntity.schoolPhone}" />
											<span class="text"></span>
										</div>
									</div>
								</div>
							</#if>

							<#if (true && editModel=='add')||(true && editModel=='edit')>
								<div class="col-xm-6 col-sm-6 col-lg-6">
									<div class="form-group">
										<label for="telephone" class="col-xm-4 col-sm-4 col-lg-4 control-label no-padding-right"><span style="color: red">*</span>园所座机：</label>
										<div class="col-xm-6 col-sm-6 col-lg-6">
											<input data-bv-message="请输入园所座机" required="required" onkeyup="inputValueLength(this,'telePhone')"
												   name="telephone" alt="园所座机" id="telephone" placeholder="园所座机"
												   type="text" title="园所座机" class="form-control"  value="${editEntity.telephone}" />
											<span class="text"></span>
										</div>
									</div>
								</div>
							</#if>
						</div>

						<div class="col-xm-12 col-sm-12 col-lg-12">
							<#if (true && editModel=='add')||(true && editModel=='edit')>
								<div class="col-xm-6 col-sm-6 col-lg-6">
									<div class="form-group">
										<label for="enterpriseMail" class="col-xm-4 col-sm-4 col-lg-4 control-label no-padding-right"><span style="color: red">*</span>企业邮箱：</label>
										<div class="col-xm-6 col-sm-6 col-lg-6">
											<input data-bv-message="请输入企业邮箱" required="required"
												   data-bv-regexp="true"
												   data-bv-regexp-regexp="^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$"
												   data-bv-regexp-message="请输入正确的企业邮箱!"
												   name="enterpriseMail" alt="企业邮箱" id="enterpriseMail" placeholder="企业邮箱"
												   type="email" title="企业邮箱" class="form-control"  value="${editEntity.enterpriseMail}" />
											<span class="text"></span>
										</div>
									</div>
								</div>
							</#if>
							<#if (true && editModel=='add')||(true && editModel=='edit')>
								<div class="col-xm-6 col-sm-6 col-lg-6">
									<div class="form-group">
										<label for="schoolQQ" class="col-xm-4 col-sm-4 col-lg-4 control-label no-padding-right">园所QQ：</label>
										<div class="col-xm-6 col-sm-6 col-lg-6">
											<input data-bv-message="The field is not valid" name="schoolQQ" alt="园所QQ" onkeyup="inputValueLength(this,'QQ')"
												   id="schoolQQ" placeholder="园所QQ" type="text" title="园所QQ"
												   class="form-control" value="${editEntity.schoolQQ}"/>
											<span class="text"></span>
										</div>
									</div>
								</div>
							</#if>
						</div>

						<div class="col-xm-12 col-sm-12 col-lg-12">
							<#if (true && editModel=='add')||(true && editModel=='edit')>
								<div class="col-xm-6 col-sm-6 col-lg-6">
									<div class="form-group">
										<label for="schoolWeichat" class="col-xm-4 col-sm-4 col-lg-4 control-label no-padding-right">园所微信：</label>
										<div class="col-xm-6 col-sm-6 col-lg-6">
											<input data-bv-message="The field is not valid" name="schoolWeichat" onkeyup="inputValueLength(this,'WeChat')"
												   alt="园所微信" id="schoolWeichat" placeholder="园所微信" type="text"
												   title="园所微信" class="form-control"
												   value="${editEntity.schoolWeichat}"/>
											<span class="text"></span>
										</div>
									</div>
								</div>
							</#if>
						</div>


						<#if (true && editModel=='add')||(false && editModel=='edit')>
							<div class="col-xm-12 col-sm-12 col-lg-12 padding-left-30">
								<hr/>
							</div>
						</#if>


						<#if (true && editModel=='add')||(false && editModel=='edit')>
							<div class="col-xm-12 col-sm-12 col-lg-12">
								<div class="col-xm-6 col-sm-6 col-lg-6">
									<div class="form-group">
										<label for="schoolAccount"
											   class="col-xm-4 col-sm-4 col-lg-4 control-label no-padding-right">园长账号：</label>
										<div class="col-xm-6 col-sm-6 col-lg-6">
											<!--<input name="schoolAccount" alt="园所账号" id="schoolAccount"
												   onblur="checkAccountIsSame(this)" onkeyup="inputValueLength(this,'account')"
												   data-id="${editEntity.id}"
												   placeholder="园所账号" type="text"
												   title="园所账号" class="form-control"/>
											<span class="text"></span>-->

											<input data-bv-remote="true"
												   data-bv-remote-url="sysAdminUserController/verificationUserName.do?id=${editEntity.id}"
												   data-bv-remote-message="账号名称已存在！"
												   data-bv-message="请填写账号名称！"  name="schoolAccount" alt="账号名称"
												   onkeyup="inputValueLength(this,'account')"
												   id="schoolAccount" placeholder="账号名称" type="text" title="账号名称"
												   class="form-control" value="${editEntity.schoolAccount}"/>
											<span class="text"></span>
										</div>
									</div>
								</div>
								<div class="col-xm-6 col-sm-6 col-lg-6">
									<div class="form-group">
										<label for="schoolPhone"
											   class="col-xm-4 col-sm-4 col-lg-4 control-label no-padding-right">联系电话：</label>
										<div class="col-xm-6 col-sm-6 col-lg-6">
											<input data-bv-message="The field is not valid" name="accountPhone" onblur="checkPhoneIsSame(this)" onkeyup="inputValueLength(this,'phone')"
												   alt="联系电话" id="accountPhone" placeholder="联系电话" type="text"
												   title="联系电话" class="form-control"/>
											<span class="text"></span>
										</div>
									</div>
								</div>
							</div>
							<div class="col-xm-12 col-sm-12 col-lg-12">
								<div class="col-xm-6 col-sm-6 col-lg-6">
									<div class="form-group">
										<label for="educationalAccount"
											   class="col-xm-4 col-sm-4 col-lg-4 control-label no-padding-right">教务账号：</label>
										<div class="col-xm-6 col-sm-6 col-lg-6">
											<!--<input name="educationalAccount" alt="教务账号" onkeyup="inputValueLength(this,'account')"
												   id="educationalAccount" placeholder="教务账号" type="text" title="教务账号"
												   onblur="checkAccountIsSame(this)"
												   class="form-control"/>
											<span class="text"></span>-->

											<input data-bv-remote="true"
												   data-bv-remote-url="sysAdminUserController/verificationUserName.do?id=${editEntity.id}"
												   data-bv-remote-message="账号名称已存在！"
												   data-bv-message="请填写账号名称！"  name="educationalAccount" alt="账号名称"
												   onkeyup="inputValueLength(this,'account')"
												   id="educationalAccount" placeholder="账号名称" type="text" title="账号名称"
												   class="form-control" value="${editEntity.educationalAccount}"/>
											<span class="text"></span>
										</div>
									</div>
								</div>
								<div class="col-xm-6 col-sm-6 col-lg-6">
									<div class="form-group">
										<label for="educationalPhone"
											   class="col-xm-4 col-sm-4 col-lg-4 control-label no-padding-right">联系电话：</label>
										<div class="col-xm-6 col-sm-6 col-lg-6">
											<input data-bv-message="The field is not valid" name="educationalPhone"
												   alt="联系电话" id="educationalPhone" placeholder="联系电话" type="text" onkeyup="inputValueLength(this,'phone')"
												   title="联系电话" class="form-control"/>
											<span class="text"></span>
										</div>
									</div>
								</div>
							</div>
							<div class="col-xm-12 col-sm-12 col-lg-12">
								<div class="col-xm-12 col-sm-12 col-lg-12">
									<div class="form-group">
										<label for="userPassword" class="col-xm-2 col-sm-2 col-lg-2 control-label no-padding-right">账号密码：</label>
										<div class="col-xm-7 col-sm-7 col-lg-7">
											<input data-bv-message="The field is not valid" style="width: 40%" onkeyup="inputValueLength(this,'password')"
												   name="userPassword" alt="账号密码" id="userPassword" placeholder="账号密码"
												   type="password" title="账号密码" class="form-control float-left"/>
											<label style="float: right;line-height: 30px;">密码为空时，使用初始密码：qzy123456</label>
											<span class="text"></span>
										</div>
									</div>
								</div>
							</div>
						</#if>
						<div class="col-sm-12">
							<div class="text-align-center ">
								<button style="min-width: 80px;margin-right:20px;" type="submit" class="btn btn-blue" id="editFormSubmitBtn_${serializeNum}">保存</button>
								<button style="width: 80px" type="button" class="btn btn-blue" data-dismiss="modal">返回</button>
							</div>
						</div>
					</form>
				</div>
			</div>
		</div>
<script src="assets/js/validation/bootstrapValidator_init.js"></script>
<script>
$(".selectpicker_${serializeNum}").select2();
/**
 * 保存
 **/
$("#editForm_${serializeNum}").bind("ajaxSubmitCallback", function (event, result) {
    if (result.resCode == 200) {
        bootbox.hideAll();
        logger.info(result.resMsg, true);
        toView('sysSchoolController/sysSchoolList.do',true,'POST',{pageSize:10})
    } else {
        logger.error(result.resMsg);
    }
});
/**
 * 获取省
 */
$(function () {
    ajaxRequest("sysCitysController/provinceList.do", null, function (result) {
        var data = result.data;
        var arr = ['<option value="">请选择</option>'];
        var value = $("#editSchoolProvince").attr("value");
        console.log(value)
        $.each(data, function (i, t) {
            if( value == t.id){
                arr.push('<option value="'+t.id+'" selected="selected">'+t.name+'</option>')
            } else {
                arr.push('<option value="'+t.id+'">'+t.name+'</option>')
            }
        })
		if(value){
            ajaxRequest("sysCitysController/getChildrens.do", {
                pId: value
            }, function (result) {
                var data = result.data;
                var arr = ['<option value="">请选择</option>'];
                var value = $("#editSchoolCity").attr("value");
                $.each(data, function (i, t) {
                    if( value == t.id){
                        arr.push('<option value="'+t.id+'" selected="selected">'+t.name+'</option>')
                    } else {
                        arr.push('<option value="'+t.id+'">'+t.name+'</option>')
                    }
                })
				if(value){
                    ajaxRequest("sysCitysController/getChildrens.do", {
                        pId: value
                    }, function (result) {
                        var data = result.data;
                        var arr = ['<option value="">请选择</option>'];
                        var value = $("#editSchoolRegion").attr("value");
                        $.each(data, function (i, t) {
                            if( value == t.id){
                                arr.push('<option value="'+t.id+'" selected="selected">'+t.name+'</option>')
                            } else {
                                arr.push('<option value="'+t.id+'">'+t.name+'</option>')
                            }
                        })
                        $(".editSchoolRegion").html(arr.join(''))

                    }, function () {
                        ajaxError("加载城区失败")
                    }, "get", "json")
				}
                $(".editSchoolCity").html(arr.join(''))

            }, function () {
                ajaxError("加载城市失败")
            }, "get", "json")
		}
        $(".editSchoolProvince").html(arr.join(''))
    }, function () {
        ajaxError("加载省失败");
    }, "get", "json")
});
/**
 * 获取市
 */
$(".editSchoolProvince").change(function () {
    var nowSelectedProvince = $(this).val();
    ajaxRequest("sysCitysController/getChildrens.do", {
        pId: nowSelectedProvince
    }, function (result) {
        var data = result.data;
        var arr = ['<option value="">请选择</option>'];
        $.each(data, function (i, t) {
            arr.push('<option value="' + t.id + '">' + t.name + '</option>')
        })
        $(".editSchoolCity").html(arr.join(''))

    }, function () {
        ajaxError("加载城市失败")
    }, "get", "json")
});
/**
 * 获取区
 */
$(".editSchoolCity").change(function () {
    var nowSelectedProvince = $(this).val();
    ajaxRequest("sysCitysController/getChildrens.do", {
        pId: nowSelectedProvince
    }, function (result) {
        var data = result.data;
        var arr = ['<option value="">请选择</option>'];
        $.each(data, function (i, t) {
            arr.push('<option value="' + t.id + '">' + t.name + '</option>')
        })
        $(".editSchoolRegion").html(arr.join(''))

    }, function () {
        ajaxError("加载城区失败")
    }, "get", "json")
});


/**
 * 表单校验
 */
function inputValueLength(that,type) {
    if(type == 'noSymbol'){
        if (/[-=;,./!@#$%^&*(){}:<>?_+！￥…（）：《》？|—\[\]]/.test(that.value)) {
            $(that).val(that.value.replace(/[-=;,./!@#$%^&*(){}:<>?_+！￥…（）：《》？|—\[\]]/g, ""));
            logger.error("输入格式不正确!");
        } else {
			if (that.value.replace(/[^\x00-\xff]/g, "aa").length > 40) {
                $(that).val(that.value.substring(0,40));
                logger.error("长度超过限制!");
			}
		}
	}
	if (type == 'englishNumber') {
        if (/[^\a-\z\A-\Z0-9]/g.test(that.value)) {
            $(that).val(that.value.replace(/[^\a-\z\A-\Z0-9]/g, ""));
            logger.error("输入格式不正确!");
        } else {
            if (that.value.replace(/[^\x00-\xff]/g, "aa").length > 20) {
                $(that).val(that.value.substring(0,20));
                logger.error("长度超过限制!");
            }
        }
	}
	if (type == 'telePhone') {
        if (/[^0-9]/g.test(that.value)) {
            $(that).val(that.value.replace(/[^0-9]/g, ""));
            logger.error("输入格式不正确!");
        } else {
            if (that.value.replace(/[^\x00-\xff]/g, "aa").length > 12) {
                $(that).val(that.value.substring(0,12));
                logger.error("长度超过限制!");
            }
        }
	}
	if (type == 'QQ') {
        if (/[^1-9][0-9]/g.test(that.value)) {
            $(that).val(that.value.replace(/[^1-9][0-9]/g, ""));
            logger.error("输入格式不正确!");
        } else {
            if (that.value.replace(/[^\x00-\xff]/g, "aa").length > 10) {
                $(that).val(that.value.substring(0,10));
                logger.error("长度超过限制!");
            }
        }
    }
    if (type == 'WeChat') {
        if (/[^\a-\z\A-\Z0-9_]/g.test(that.value)) {
            $(that).val(that.value.replace(/[^\a-\z\A-\Z0-9_]/g, ""));
            logger.error("输入格式不正确!");
        } else {
            if (that.value.replace(/[^\x00-\xff]/g, "aa").length > 20) {
                $(that).val(that.value.substring(0,20));
                logger.error("长度超过限制!");
            }
        }
    }
    if (type == 'account') {
        if (/[^\a-\z\A-\Z0-9_]/g.test(that.value)) {
            $(that).val(that.value.replace(/[^\a-\z\A-\Z0-9_]/g, ""));
            logger.error("输入格式不正确!");
        } else {
            if (that.value.replace(/[^\x00-\xff]/g, "aa").length > 20) {
                $(that).val(that.value.substring(0,20));
                logger.error("长度超过限制!");
            }
        }
    }
    if (type == 'phone') {
        if (/[^0-9]/g.test(that.value)) {
            $(that).val(that.value.replace(/[^0-9]/g, ""));
            logger.error("输入格式不正确!");
        } else {
            if (that.value.replace(/[^\x00-\xff]/g, "aa").length > 11) {
                $(that).val(that.value.substring(0,11));
                logger.error("长度超过限制!");
            }
        }
    }
    if (type == 'password') {
        if (/[^\a-\z\A-\Z0-9]/g.test(that.value)) {
            $(that).val(that.value.replace(/[^\a-\z\A-\Z0-9]/g, ""));
            logger.error("输入格式不正确!");
        } else {
            if (that.value.replace(/[^\x00-\xff]/g, "aa").length > 16) {
                $(that).val(that.value.substring(0,16));
                logger.error("长度超过限制!");
            }
        }
    }
}
</script>